import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // 重定向，重定向的是：路由的路径，不是文件名
    // redirect: '/login'
    // 打开网页就进入首页
    redirect: '/layout'
  },
  {
    path: '/login',
    // 路由懒加载: 当路由匹配/login以后, 才去加载Login里的js等资源
    component: () => import('@/views/Login')
  },
  {
    path: '/layout',
    component: () => import('@/views/Layout'),
    // 打开layout的时候默认去home路径下
    redirect: '/layout/home',
    children: [
      {
        path: 'home',
        component: () => import('@/views/Home')
      },
      {
        path: 'user',
        component: () => import('@/views/User')
      }
    ]
  },
  {
    path: '/search',
    component: () => import('@/views/Search')
  },
  {
    // 参数名，路径和是哪个传递具体值到这里
    path: '/search/:keywords',
    component: () => import('@/views/SearchResult')
  },
  {
    path: '/art_detail',
    component: () => import('@/views/Article')
  },
  {
    path: '/user_edit',
    component: () => import('@/views/User/UserEdit')
  }
]

const router = new VueRouter({
  routes
})

export default router
